
const express = require('express');
const router = express.Router();

const Record = require('../Model/RecordSchema');
const Problem = require('../Model/ProblemPoolSchema');
const { generateMonthCalendar } = require('../utils/index')

router.get('/allRecords', async function (req, res) {
  // express 中 通过query获取数据
  const { year, month } = req.query;

  try {
    const record = await Record.findRecord(year, month);
    const monthCalendar = generateMonthCalendar(record, year, month);
    res.json({
      status: 200,
      msg: "record found",
      monthCalendar: monthCalendar
    });
  } catch (e) {
    res.json({ status: 404, msg: e.message })
  }
})

router.get("/md/:type", async function (req, res) {
  const { type } = req.params;
  try {
    const allRes = await Problem.findByType(type);
    res.json({
      status: 200,
      data: allRes
    })
  } catch (e) {
    res.json({ status: 404, msg: e.message })
  }
})


module.exports = router;